package com.example.smartcity_40.Fragment;

import android.content.Context;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.ViewPager2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.smartcity_40.R;
import com.example.smartcity_40.service.apter.ServiceIMGApter;
import com.example.smartcity_40.service.bean.ServiceIMGBean;
import com.example.smartcity_40.tool.Tool;

import java.util.ArrayList;

import kotlin.Unit;
import kotlin.jvm.functions.Function1;

public class ServiceFragment extends Fragment {

    private View view;
    private FragmentActivity activity;
    private Context context;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_service, container, false);
        activity = getActivity();
        context = getContext();
        initview();
        return view;
    }

    private void initview() {
        RecyclerView servicelist = view.findViewById(R.id.servicelist);
        Tool tool = new Tool(context);
        ServiceIMGApter serviceIMGApter = new ServiceIMGApter(context);
        tool.send("/prod-api/api/service/list",
                tool.GET,
                null,
                false,
                ServiceIMGBean.class,
                new Function1<ServiceIMGBean, Unit>() {
                    @Override
                    public Unit invoke(ServiceIMGBean serviceIMGBean) {
                        if(serviceIMGBean.getCode()==200){


                            ServiceIMGBean.RowsDTO rowsDTO = new ServiceIMGBean.RowsDTO();
                            rowsDTO.setId(99);
                            rowsDTO.setImgUrl(serviceIMGBean.getRows().get(0).getImgUrl());
                            rowsDTO.setServiceName("律师咨询");
                            serviceIMGBean.getRows().add(rowsDTO);


                            servicelist.setLayoutManager(new GridLayoutManager(context,5));
                            serviceIMGApter.setDate(serviceIMGBean.getRows());
                            servicelist.setAdapter(serviceIMGApter);
                       }
                        return null;
                    }
                });
    }
}